import copy
import itertools


def generate_dna_sequences(len: int):
    bases = ['A', 'T', 'G', 'C']
    # 生成指定长度的所有可能组合
    sequences = [''.join(seq) for seq in itertools.product(bases, repeat=len)]
    # 对生成的序列进行排序
    sorted_sequences = sorted(sequences)
    return sorted_sequences


def dna_sequence():
    while True:
        while True:
            loop = input("输入特定长度(1-12),(q退出)：")
            if loop == 'q':
                print("已退出程序")
                return
            elif loop.isdigit():
                loop = int(loop)
                if loop <= 0 or loop > 12:
                    print("指令不正确，请重新输入")
                else:
                    break
            else:
                print("指令不正确，请重新输入")
        # param = ['A', 'G', 'C', 'T']
        # all_str = ['']
        # for i in range(1, loop + 1):
        #     temp_list = copy.deepcopy(all_str)
        #     all_str = []
        #     for a in temp_list:
        #         for p in param:
        #             all_str.append(a + p)
        # print(len(all_str))
        result = generate_dna_sequences(loop)
        print(result)
        print("共有{}种组合".format(len(result)))


dna_sequence()
